<!DOCTYPE html>  
<html lang="en">  
<head>  
    <meta charset="UTF-8">  
    <title>AES加密</title>  
  
</head>  
  
<script src="../js/lib/aes.min.js" type="text/javascript" charset="utf-8"></script>
<body>  
  
  
<script>  
  
     
  
    var key = CryptoJS.enc.Utf8.parse("!@#987321ascwfds");  
  
    var plaintText = '1234567'; // 明文  
  
    var encryptedData = CryptoJS.AES.encrypt(plaintText, key, {  
        mode: CryptoJS.mode.ECB,  
        padding: CryptoJS.pad.Pkcs7  
    });  
  
    console.log("加密前："+plaintText);  
    console.log("加密后："+encryptedData);  
  
    encryptedData = encryptedData.ciphertext.toString();  
  
    var encryptedHexStr = CryptoJS.enc.Hex.parse(encryptedData);  
    var encryptedBase64Str = CryptoJS.enc.Base64.stringify(encryptedHexStr);  
  
    var decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, {  
        mode: CryptoJS.mode.ECB,  
        padding: CryptoJS.pad.Pkcs7  
    });  
  
    var decryptedStr = decryptedData.toString(CryptoJS.enc.Utf8);  
  
    console.log("解密后:"+decryptedStr);  
  
      
     var pwd = "PCsUFtgog9/qpqmqXsuCRQ==";  
    //加密服务端返回的数据  
    var decryptedData = CryptoJS.AES.decrypt(pwd, key, {  
        mode: CryptoJS.mode.ECB,  
        padding: CryptoJS.pad.Pkcs7  
    });  
      
    console.log("解密服务端返回的数据:"+decryptedStr);  
  
</script>  
</body>  
</html>  